import koaRouter from 'koa-router'
import { errorRes, successRes } from '@/utils/responseModel'
import { CustomRouterContext } from '.'
import { dataSource } from '@/utils/typeormConnect'
import { User } from '@/model/User'

const router = new koaRouter<any, CustomRouterContext>()

router.prefix('/user')

const userRepository = dataSource.getRepository(User)

router.post('/getUserInfo', async (ctx, next) => {

    await userRepository
        .createQueryBuilder()
        .select()
        .where('id = :userId', { userId: ctx.global.tokenInfo.userId })
        .andWhere('state = 1')
        .getOne()
        .then(r => {
            ctx.body = new successRes(r!)
        })
})

export default router